package com.aatrox.bhsypro.controller;

import com.aatrox.bhsypro.entity.BMySelf;
import com.aatrox.bhsypro.entity.BUser;
import com.aatrox.bhsypro.entity.CollectVideo;
import com.aatrox.bhsypro.service.UCollectService;
import com.aatrox.bhsypro.util.CookieUtil;
import com.aatrox.bhsypro.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.swing.*;
import java.util.HashMap;
import java.util.List;

/**
 * 个人首页 控制层
 */
@RestController
public class BMySelfAjaxController {


    @Autowired
    RedisTemplate<String,Object> redisTemplate;
    @Autowired
    UCollectService ucs;
    @PostMapping(value = "/bmColl")
    public JsonResult bmColl(HttpServletRequest request, String cName, HttpSession session){
        String ticket = CookieUtil.getCookieValue(request,"userTicket");
        BUser user = (BUser) redisTemplate.opsForValue().get("user:"+ticket+"uid:"+(session.getAttribute("buserId")));
        HashMap hm = new HashMap();
        hm.put("uid",user.getUid());
        hm.put("cName",cName);
        List<CollectVideo> list = ucs.selCollectMsg(hm);
        hm.clear();
        hm.put("collectMsg",list);
        return new JsonResult(200,"查询收藏夹成功",hm);
    }
}
